import { useEffect, useState } from "react";
import styles from "./index.module.scss";
import { getNewsDesc } from "@/request/api";
import { useParams } from "react-router-dom";
import { getFormatTime } from "@/utils";

export default function NewsDesc() {
  const [dataSource, setDataSource]: any = useState({});
  const { id } = useParams();

  useEffect(() => {
    getNewsDesc(id).then((res: any) => {
      setDataSource(res);
    });
  }, []);

  return (
    <div
      style={{
        backgroundColor: "#c1e1fd",
        minHeight: "100vh",
      }}
    >
      <div className={styles.descBox}>
        <div className={styles.descTitle}>{dataSource.title}</div>
        <div className={styles.descTime}>
          {getFormatTime(dataSource.created_at)}
        </div>
        <div className={styles.descContent}>
          <div dangerouslySetInnerHTML={{ __html: dataSource.content }} />
        </div>
      </div>
    </div>
  );
}
